package com.SmartCare.mapper.medicine;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.SmartCare.common.vo.medicine.MedicationRecordVo;
import com.SmartCare.pojo.medicine.MedicationRecord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 *  Mapper 接口
 */
@Mapper
public interface MedicationRecordMapper extends BaseMapper<MedicationRecord> {


        /*
        SELECT c.name,a.time,e.bed_number,a.list_num,c.id medication_id
        FROM medication_record a, medication_list b,medication c ,elderly_information e
    WHERE (a.medication_list_id=b.id
    AND a.list_num=b.list_num
    AND b.elderly_id=e.elderly_id
    AND b.medication_id=c.id
    AND a.id IN (1,2)
    AND a.status = false
    ) ORDER BY a.time ASC ;
         */
     @Select("<script>"+"SELECT c.name name,a.time time,e.bed_number bedNumber,a.list_num listNum,c.id medicationId,e.elderly_id elderlyId  " +
            "FROM medication_record a, medication_list b,medication c ,elderly_information e " +
            "WHERE (a.medication_list_id=b.id " +
            "AND a.list_num=b.list_num " +
            "AND b.elderly_id=e.elderly_id " +
            "AND b.medication_id=c.id " +
            "AND a.id IN("+ " <foreach collection='ids' separator=',' item='id'>"+ "#{id} "+ "</foreach> "+ ")"+
            "AND a.status = false " +
            ") ORDER BY a.time ASC ; "+"</script>")
     List<MedicationRecordVo> getNameAndId(List<Long> ids);
}
